package com.zerdoor.controller;

import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.FundManageService;
import com.zerdoor.service.PlatformFinanceReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 平台财务报表
 * Created by zhongjieyu on 2015/1/29.
 */
@Controller
@RequestMapping("/platformFinance")
public class PlatformFinanceReportController {


    @Autowired
    private PlatformFinanceReportService platformFinanceReportService;


    /**
     * 跳转到用户财务报表首页
     * @param request
     * @return
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(HttpServletRequest request){



        return "/fundManage/platformFinance";
    }

    /**
     * 查询统计平台财务数据
     * @param request 状态
     * @return
     */
    @RequestMapping(value = "/findCountPlatformFinance", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findCountPlatformFinance(HttpServletRequest request){

        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put("beginTime",request.getParameter("beginTime"));
            result.put("endTime",request.getParameter("endTime"));
            result.put("costType",request.getParameter("costType"));

            //得到汇总金额
            float sumPrice = platformFinanceReportService.findCountPlatformFinance(result);

            result.put("sumPrice",sumPrice);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询统计失败！");
            return result;
        }
        return result;
    }


    /**
     * 分页查询平台财务明细报表
     * @param request
     * @return
     */
    @RequestMapping(value = "/findPlatformFinanceReport", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findPlatformFinanceReport(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("beginTime",request.getParameter("beginTime"));
        result.put("endTime",request.getParameter("endTime"));
        result.put("costType",request.getParameter("costType"));
        List<Map> list = null;
        try {

            list = platformFinanceReportService.findPlatformFinanceReport(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }


}
